require 'benchmark'

points = [[1,2], [4,5], [1,0], [4,1], [1,-1]]
  
points = (1..10000).map { [rand(100), rand(100)] }

p_sorted1, p_sorted2, p_sorted3 = [], [], []
  
time = Benchmark.realtime do
  p_sorted1 = points.sort do |p1,p2|
  #p %Q[#{p1[0]} , #{p2[0]}]
    #ret = 0
    ret = p1[0] <=> p2[0] if p1[0] != p2[0]
    ret = p1[1] <=> p2[1] if p1[0] == p2[0]
    ret
  end
end

p "sort1 takes: #{time*1000} milli sec"

time = Benchmark.realtime do
p_sorted2 = points.sort_by do |p|
  [p[0], p[1]]
end
end

p "sort2 takes: #{time*1000} milli sec"

time = Benchmark.realtime do
p_sorted3 = points.sort_by {|p| p}
end

p "sort3 takes: #{time*1000} milli sec"

p p_sorted1

p p_sorted2

p p_sorted3



